<template>
  <el-container>
    <el-header>
      <el-menu
        :default-active="pageActive"
        :router="true"
        class="el-menu-vertical-demo"
        mode="horizontal"
      >
        <el-menu-item :index="item.path" :key="i" v-for="(item,i) in menus">
          <i :class="item.eIcon"></i>
          <span slot="title">{{item.name}}</span>
        </el-menu-item>
      </el-menu>
    </el-header>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      corpId: "",
      code: "",
      menus: [],
      pageActive: "/empSalary"
    };
  },
  created: function() {
    //进入页面先获取免登code
    this.getJsApiTeckit();
    this.pageActive = this.$route.path;
  },
  methods: {
    async getJsApiTeckit() {
      var result = await this.$httpd.get("/DingDingSecurity/GetJsapiTicket");
      if (result.status != 200) {
        this.$message.error("获取钉钉信息出错");
        return;
      }
      this.corpId = result.data.corpId;
      this.getCode(this.corpId);
    },
    //获取个人免登code
    getCode(corpId) {
      var that = this;
      that.$dd.ready(() => {
        that.$dd.runtime.permission.requestAuthCode({
          corpId: corpId, // 企业id
          onSuccess: function(info) {
            //alert(info.code); // 通过该免登授权码可以获取用户身份
            // console.log(info.code);
            that.code = info.code;
            //调用获取菜单
            that.getMenu(that.code);
          }
        });
      });
    },
    //获取菜单
    async getMenu(code) {
      var menuResult = await this.$httpd.get(
        `/DingDingSecurity/GetMenuList?code=${code}`
      );
      if (menuResult.status != 200) {
        this.$message.error("获取用户菜单列表出错");
        return;
      }
      this.menus = menuResult.data;
    }
  }
};
</script>

<style scoped>
.app,
.el-menu,
.el-container,
.el-main {
  height: 100%;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  padding: 0;
}

body > .el-container {
  margin-bottom: 40px;
}
</style>